class_name TileHighlighter
extends Node

# ===============================================

@export var enabled: bool :
	set(value):
		enabled = value
		if not enabled and play_area:
			highlight_layer.clear()

@export var tile: Vector2i
@export var play_area: PLayArea
@export var highlight_layer: TileMapLayer

# ===============================================

@onready var source_id := play_area.tile_set.get_source_id(0)

# ===============================================

func _process(_delta: float) -> void:
	if not enabled:
		return
	
	highlight_layer.clear()	
	var selected_tile: Vector2i = play_area.get_hovered_tile()
	
	if not play_area.is_tile_in_bounds(selected_tile):
		return
	
	highlight_layer.set_cell(selected_tile, source_id, tile)
